package com.baizhi.controller;

import com.baizhi.entity.Title;
import com.baizhi.service.TitleService;
import com.baizhi.util.Bto;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class TitleController {
    @Autowired
    private TitleService ts;
    @GetMapping("titles")
    public Map<String,Object> page(int page,int limit){
        final PageInfo<Title> titlePageInfo = ts.selectPage(page, limit);
        return  new HashMap(){{
            put("msg","");
            put("data",titlePageInfo.getList());
            put("count",titlePageInfo.getTotal());
            put("code",0);
        }};
    }
    @PostMapping("Btos")
    public void insertAll(@RequestBody Bto b){
        System.out.println(b);
        ts.insertAll(b);
    }
}
